#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    setMinimumSize(500,300);
    mk = new mywork("华强");
    mt = new QThread();
    mk->moveToThread(mt);
    connect(mt,&QThread::finished,this,&QObject::deleteLater);
    connect(mk,&mywork::workresult,this,&Widget::workResult);
    connect(this,&Widget::startWork,mk,&mywork::workstart);
    connect(btn,&QPushButton::clicked,this,[=](){
        emit startWork("做PPT");
    });
    mt->start();

    gid->addWidget(btn,0,0,1,2);
    gid->addWidget(ts,1,0,3,2);
}

Widget::~Widget()
{
    if(mt->isRunning())
    {
        mt->quit();
        mt->exit();
    }
    this->deleteLater();
}

void Widget::workResult(QString ret)
{
    qDebug () << "main 主线程id ：" << QThread::currentThreadId();
    ts->append(ret);
}

